import { _decorator, Component, Node } from 'cc';
import {
    HttpUtils,
    IHttpMethod,
} from 'db://assets/component/Net/HttpUtils';
const { ccclass, property } = _decorator;

@ccclass('HttpTest')
export class HttpTest extends Component {
    start() {}

    update(deltaTime: number) {}

    // 发送get请求
    getData() {
        const pragma = { id: 0, name: 'hello' };
        HttpUtils.request('http://127.0.0.1:12000/', pragma, (data: any) => {
            console.log('get', data);
        });
    }

    // 发送post请求
    postData() {
        const pragma = { id: 0, name: 'hello' };
        HttpUtils.request(
            'http://127.0.0.1:12000/',
            pragma,
            (data: any) => {
                console.log('post', data);
            },
            IHttpMethod.POST,
        );
    }

    onGetData() {}

    onPostData() {}
}
